<?php
/*
Plugin Name: WP-ThemeList
Plugin URI: http://www.thegentootux.com
Description: Displays a list of the active themes - just insert [themes list] in posts or pages, betweebìn <ul> and </ul>. If you want to show also the themes that you have installed but are not presently using, just insert [themes list all]. Only one theme list allowed for post or page.
Version: 0.1
Author: Jacob Langley
Author URI: http://www.thegentootux.com
*/
/*  Copyright 2008  Jacob Langley (email : jacob.langley@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
$my_plugins_version = "0.1";

if (!function_exists('add_filter'))
	die ("Hello World!");

if (!function_exists('get_themes'))
	require_once (ABSPATH."wp-admin/includes/theme.php");

add_filter('the_content', 'jlangley_themes');

function jlangley_themes ($content) {
			global $post, $plugin_css_displayed;
			$show_inactive_plugins = FALSE;
			$active_tag = "[themes list]";
			$all_tag = "[themes list all]";
			if (!strstr($content, $active_tag) && !strstr($content, $all_tag))
				return $content;
            if (strstr($content, $active_tag)) { 
				$actual_tag = $active_tag;
			} else { 
				$actual_tag = $all_tag;
				$show_inactive_themes = TRUE;
				}
			$themes = get_themes ();				
			
			if (empty($themes)) {
				echo '<p>';
				_e("Couldn&#8217;t open themes directory or there are no themes available."); // TODO: make more helpful
				echo '</p>';
			} else {
			ob_start();
			$i = 1;
			?>
			
			<?php
				$style = '';
			    
				foreach($themes as $theme_file => $theme_data) {
					$themes_allowedtags1 = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
					$themes_allowedtags2 = array('abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
			
					// Sanitize all displayed data
					$theme_data['Title']       = wp_kses($theme_data['Title'], $themes_allowedtags1);
					$theme_data['Version']     = wp_kses($theme_data['Version'], $themes_allowedtags1);
					$theme_data['Author']      = wp_kses($theme_data['Author'], $themes_allowedtags1);
					
					if ($show_inactive_themes | get_current_theme() == $theme_data['Title']) {
					   echo "<li>{$theme_data['Title']} (v. {$theme_data['Version']} ) by {$theme_data['Author']}.</li>";
					}
				 $i++;
				}
				
			?>
		
		    
<?php 			
        $ret = ob_get_contents();
        ob_end_clean ();
        return str_replace ($actual_tag, $ret, $content);
     }
}
?>
